#include<bits/stdc++.h>
using namespace std;
int n,cnt[1000005];
bool son[1000005];
int siz[1000005],dep[1000005],ch[1000005][2],tot=1;
string str;
priority_queue<pair<int,bool>,vector<pair<int,bool> >,greater<pair<int,bool> > >q[100005];
void dfs(int u){
	if(u==0)return;
	siz[u]=1;
	int chl=ch[u][0],chr=ch[u][1];
	if(chl){dep[chl]=dep[u]+1;dfs(chl);}if(chr){dep[chr]=dep[u]+1;dfs(chr);}
	siz[u]+=siz[chl];siz[u]+=siz[chr];
	if(siz[chl]<siz[chr])son[u]=1;
}
long long ans;
void dfs2(int u){
//	cout<<"rt:"<<u<<" "<<cnt[u]<<"\n";
	int chl=ch[u][0],chr=ch[u][1];
	int sl=chl,sr=chr;
	if(chl)dfs2(chl);if(chr)dfs2(chr);
//	cout<<"out"<<" "<<chl<<" "<<chr<<'\n';
	if((sl!=0)^(sr!=0)){
//		cout<<"in1\n";
		if(sl){q[u]=q[sl];}
		if(sr){q[u]=q[sr];}
		q[u].push({dep[u]+1,1});	
	}else{
//cout<<"in2\n";
		if(((sl==0)&&(sr==0))){
			cnt[u]--;
			q[u].push({dep[u]+2,0});
		}else{
			if(!son[u]){
				q[u]=q[chl];
				while(!q[chr].empty()){
					q[u].push(q[chr].top());
					q[chr].pop();
//					cout<<"xinggantlh\n";
				}
//				q[chr].clear();
			}else {
				q[u]=q[chr];
				while(!q[chl].empty()){
					q[u].push(q[chl].top());
					q[chl].pop();
				}
//				q[chl].clear();
			}
		}
	}
//	cout<<cnt[u]<<"\n";
	while(cnt[u]){
		cnt[u]--;
//		cout<<cnt[u]<<"yy\n";
		pair<int,bool>Q=q[u].top();q[u].pop();
		ans+=Q.first-dep[u];
//		cout<<u<<" "<<Q.first<<" "<<Q.second<<'\n';
		if(Q.second==0){
			q[u].push({Q.first+1,0});
			q[u].push({Q.first+1,0});
		}else{
			q[u].push({Q.first+2,0});
		}
	}
	return;
}
int main(){
	freopen("id.in","r",stdin);
	freopen("id.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;dep[1]=1;
	for(int i=1;i<=n;i++){
		cin>>str;
		int root=1;
		for(int j=0;j<str.size();j++){
			if(!ch[root][str[j]-'0'])ch[root][str[j]-'0']=++tot;
			root=ch[root][str[j]-'0'];
		}
		cnt[root]++;
	}
	dfs(1);
//	cout<<"tlh\n";
	dfs2(1);
	
	cout<<ans<<"\n";
}

